package govenor.status;

import govenor.overwatch.FileStoreNode;

import java.util.List;

import constants.NetworkConstants;

import tcp.command.CommandClient;

import networkdescriptor.NetworkDescriptor;

public class StatusHandler implements Runnable{

	private StatusManager manager ;

	
	public StatusHandler(StatusManager manager){
		this.manager = manager;
	}

	public void run() {
		List<FileStoreNode> listOfCommandNodes = this.manager.getWatchedFileStores();
		if(listOfCommandNodes != null && !listOfCommandNodes.isEmpty()){
			for(int i =0; i < listOfCommandNodes.size(); i++){
				NetworkDescriptor nd = listOfCommandNodes.get(i).getCommandNetworkDescription();
				NetworkDescriptor tempNd = listOfCommandNodes.get(i).getHeartBeatNetworkDescription();
				String serverId = tempNd.getHostname()+":"+tempNd.getPortNumber();
				CommandClient.sendCommand(NetworkConstants.COMMAND_ACTON_STATUS,serverId, nd.getHostname(), nd.getPortNumber(), this.manager, null);
			}
		}
	}
}
